package com.alks.function.controller;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.entity.*;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.operate.material.*;
import com.alks.function.data.request.operate.materialIn.MtlBIStorageReq;
import com.alks.function.data.request.stock.InventoryLocFil;
import com.alks.function.data.request.stock.PcMtlStockRequest;
import com.alks.function.service.PcMtlStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * @author:xxxxx
 * @create: 2023-06-28 10:21
 * @Description: 库存
 */

@ApiRestController("/stock")
@Api(tags = {"荣阳查询 -- 库存","开发-库存位置建档","开发-材料入库作业","开发-其他入库作业","开发-材料出库作业/其他材料出库作业"})
@Slf4j
public class PcMtlStockController {
    @Autowired
    private PcMtlStockService pcMtlStockService;
    @PostMapping("/pcMtlStockList")
    @ApiOperation(value = "库存资料查询",tags = "荣阳查询 -- 库存")
    @WebLogger
    public ResponseInfo pcMtlStockList(@RequestBody PcMtlStockRequest request){
        return pcMtlStockService.pcMtlStockList(request);
    }

    @PostMapping("/downloadMtlSto")
    @ApiOperation(value = "材料库存下载",tags = "荣阳查询 -- 库存")
    @WebLogger
    public void downloadMtlSto(HttpServletResponse response,@RequestBody PcMtlStockRequest request) throws IOException {
        pcMtlStockService.downloadMtlSto(response,request);
    }

    @GetMapping(value = {"/pcMtlStockInOutList"})
    @ApiOperation(value = "出入库资料查询",tags = "荣阳查询 -- 库存")
    @WebLogger
    public ResponseInfo pcMtlStockInOutList(@RequestParam String mtlNo){
        return pcMtlStockService.pcMtlStockInOutList(mtlNo);
    }
    @GetMapping(value = {"/pcMtlStockCondition"})
    @ApiOperation(value = "库存资料条件查询",tags = "荣阳查询 -- 库存")
    @WebLogger
    public ResponseInfo pcMtlStockCondition(){
        return pcMtlStockService.pcMtlStockCondition();
    }

    @WebLogger
    @ApiOperation(value = "列表查询",tags = "开发-库存位置建档")
    @PostMapping("/wareHouseList")
    public ResponseInfo wareHouseList(@RequestBody InventoryLocFil request){
        return pcMtlStockService.wareHouseList(request);
    }

    @WebLogger
    @ApiOperation(value = "新增",tags = "开发-库存位置建档")
    @PostMapping("/insertHouse")
    public ResponseInfo insertHouse(@RequestBody InventoryLocFil request){
        return pcMtlStockService.insertHouse(request);
    }

    //删除库存位置建档
    @WebLogger
    @ApiOperation(value = "删除库存位置建档",tags = "开发-库存位置建档")
    @PostMapping("/deleteHouse")
    public ResponseInfo deleteHouse(@RequestBody InventoryLocFil request){
        return pcMtlStockService.deleteHouse(request);
    }


    @WebLogger
    @PostMapping("/in/mtlBIStorageList")
    @ApiOperation(value = "已入库资料",tags = "开发-材料入库作业")
    public ResponseInfo mtlBIStorageList(@RequestBody MtlBIStorageReq req){
        return pcMtlStockService.mtlBIStorageList(req);
    }

    //材料扫描入库
    @GetMapping("/in/scanInPcMtlIn")
    @WebLogger
    @ApiOperation(value = "扫描入库",tags = "开发-材料入库作业")
    public ResponseInfo scanInPcMtlIn(@RequestParam @ApiParam(value = "扫描单号") String slipNo){
        return pcMtlStockService.scanInPcMtlIn(slipNo);
    }

    //扫描单据资料查询
    @GetMapping("/in/getScanInSlipTemp")
    @WebLogger
    @ApiOperation(value = "扫描单据资料",tags = "开发-材料入库作业")
    public ResponseInfo getScanInSlipTemp(){
        return pcMtlStockService.getScanInSlipTemp();
    }
    //删除临时表资料
    @GetMapping("/deleteSlipInTemp")
    @WebLogger
    @ApiOperation(value = "删除临时表中数据",tags = "开发-材料入库作业")
    public ResponseInfo deleteSlipInTemp(){
        return pcMtlStockService.deleteSlipInTemp();
    }

    //生成入库单
    @PostMapping("/genericSlipNo")
    @WebLogger
    @ApiOperation(value = "生成入库单",tags = "开发-材料入库作业")
    public ResponseInfo genericSlipNo(@RequestBody List<ScanTheDocumentInformation> list){
        return pcMtlStockService.genericSlipNo(list);
    }

    //打印材料标签
    @PostMapping("/printPcMtlIn")
    @WebLogger
    @ApiOperation(value = "打印材料标签",tags = "开发-材料入库作业")
    public ResponseInfo  printPcMtlIn(@RequestBody @ApiParam(value = "入库单号") List<String> sendNos){
        return pcMtlStockService.printPcMtlIn(sendNos);
    }

    @WebLogger
    @PostMapping("/in/deleteBIStorage")
    @ApiOperation(value = "删除入库资料",tags = "开发-材料入库作业")
    public ResponseInfo deleteBIStorage(@RequestBody MtlBIStorageRep req){
        return pcMtlStockService.deleteBIStorage(req);
    }
    //开发-其他入库作业

    //MaterialOtherChoReq

    @WebLogger
    @PostMapping("/other/chooseMtlInList")
    @ApiOperation(value = "选择材料查询",tags = "开发-其他入库作业")
    public ResponseInfo chooseMtlInList(@RequestBody MaterialOtherChoReq req){
        return pcMtlStockService.chooseMtlInList(req);
    }

    @WebLogger
    @PostMapping("/other/insertMtlInList")
    @ApiOperation(value = "插入",tags = "开发-其他入库作业")
    public ResponseInfo insertMtlInList(@RequestBody List<SdMtlNewKfRep> list){
        return pcMtlStockService.insertMtlInList(list);
    }

    //其他入库作业 选择
    @WebLogger
    @GetMapping("/other/mtlOtherList")
    @ApiOperation(value = "选择",tags = "开发-其他入库作业")
    public ResponseInfo mtlOtherList(){
        return pcMtlStockService.mtlOtherList();
    }

    //删除临时表中的数据 SdMtlOtherTempRep
    @WebLogger
    @PostMapping("/other/deleteByTemp")
    @ApiOperation(value = "删除临时表中的数据",tags = "开发-其他入库作业")
    public ResponseInfo deleteByTemp(){
        return pcMtlStockService.deleteByTemp();
    }

    //查询材料其他入库明细 MaterialOtherDetailReq
    @WebLogger
    @PostMapping("/other/mtlDetailList")
    @ApiOperation(value = "材料其他入库明细",tags = "开发-其他入库作业")
    public ResponseInfo mtlDetailList(@RequestBody MaterialOtherDetailReq req){
        return pcMtlStockService.mtlDetailList(req);
    }

    //生成入库单据 slipNo：XYRKyyyyMM 4位 redis自增
    @WebLogger
    @PostMapping("/other/cOtherDetailList")
    @ApiOperation(value = "生成其他入库单据",tags = "开发-其他入库作业")
    public ResponseInfo cOtherDetailList(@RequestBody CreMtlOtherDetailReq req){
        return pcMtlStockService.cOtherDetailList(req);
    }
    //删除入库材料
    @WebLogger
    @PostMapping("/other/dOtherDetail")
    @ApiOperation(value = "删除入库材料",tags = "开发-其他入库作业")
    public ResponseInfo dOtherDetail(@RequestBody SdMtlOtherTempDetailRep req){
        return pcMtlStockService.dOtherDetail(req);
    }

    //材料出库作业 开发-材料出库作业/其他材料出库作业 PcMtlOut1Rep

    @WebLogger
    @GetMapping("/out/outMtlList")
    @ApiOperation(value = "已出库资料",tags = "开发-材料出库作业/其他材料出库作业")
    public ResponseInfo outMtlList(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        return pcMtlStockService.outMtlList(pageNum,pageSize);
    }

    //扫描单据资料
    @GetMapping("/out/scanSlipByLotNo")
    @WebLogger
    @ApiOperation(value = "扫描单据作业",tags = "开发-材料出库作业/其他材料出库作业")
    public ResponseInfo scanSlipByLotNo(@RequestParam String lotNo){
        return pcMtlStockService.scanSlipByLotNo(lotNo);
    }

    @GetMapping("/out/getScanSlipByLotNo")
    @WebLogger
    @ApiOperation(value = "查询扫描单据作业",tags = "开发-材料出库作业/其他材料出库作业")
    public ResponseInfo getScanSlipByLotNo(){
        return pcMtlStockService.getScanSlipByLotNo();
    }

    //扫描指令出库
    @PostMapping("/out/createOutSlipNo")
    @WebLogger
    @ApiOperation(value = "生成出库单",tags = "开发-材料出库作业/其他材料出库作业")
    public ResponseInfo createOutSlipNo(@RequestBody List<ScanOutDetail> list){
        return pcMtlStockService.createOutSlipNo(list);
    }
    //生成出库单

    //其它材料出库 1、选择材料  SD_MTL_NEW 查询 插入到临时表 临时表退出页面自动删除 生成其他单据 直接删除临时表中数据 删除粗出库单 查询出库单
    @WebLogger
    @PostMapping("/out/chooseMtlOtherList")
    @ApiOperation(value = "选择材料",tags = "开发-材料出库作业/其他材料出库作业")
    public ResponseInfo chooseMtlOtherList(@RequestBody MaterialOtherChoReq req){
        return pcMtlStockService.chooseMtlOtherList(req);
    }

    @WebLogger
    @PostMapping("/out/otherMtlOuts")
    @ApiOperation(value = "选择材料插入",tags = "开发-材料出库作业/其他材料出库作业")
    public ResponseInfo otherMtlOuts(@RequestBody List<PcMtlOtherOut2Rep> req){
        return pcMtlStockService.otherMtlOuts(req);
    }

    //选择材料出货明细
    @WebLogger
    @GetMapping("/out/otherMtlDetailList")
    @ApiOperation(value = "选择材料出库明细",tags = "开发-材料出库作业/其他材料出库作业")
    public ResponseInfo otherMtlDetailList(){
        return pcMtlStockService.otherMtlDetailList();
    }

    //生成出货单据
    @WebLogger
    @PostMapping("/out/creOtherMtlSlip")
    @ApiOperation(value = "生成其他出库单据",tags = "开发-材料出库作业/其他材料出库作业")
    public ResponseInfo creOtherMtlSlip(@RequestBody OtherMtlDetailOutListReq req){
        return pcMtlStockService.creOtherMtlSlip(req);
    }

    //材料其他出库明细 MtlOther2Req MtlOtherDetailOut1Rep
    @WebLogger
    @PostMapping("/out/otherDetails")
    @ApiOperation(value = "材料其他出库明细",tags = "开发-材料出库作业/其他材料出库作业")
    public ResponseInfo otherDetails(@RequestBody MtlOther2Req req){
        return pcMtlStockService.otherDetails(req);
    }

    //删除出库单
    @WebLogger
    @PostMapping("/out/deleteByOtherDetail")
    @ApiOperation(value = "删除入库单",tags = "开发-材料出库作业/其他材料出库作业")
    public ResponseInfo deleteByOtherDetail(@RequestBody MtlOtherDetailOut1Rep rep){
        return pcMtlStockService.deleteByOtherDetail(rep);
    }
}
